<?php 
function send_mail(){
	$url = 'http://sendcloud.sohu.com/webapi/mail.send_template.json';
	$vars = json_encode(
		array(
			'to' => array(1217867491@qq.com),
			'sub' => array(
				'code' => array('2345')
				)
		));
	$API_USER = '';
	$API_KEY = '';
	$param = array(
			'api_user' => $API_USER,
			'api_key' => $API_KEY,
			'from' => 'm18748342258@163.com',
			'fromname' => 'SendCloud',
			'substitution_vars' =>$vars,
			'template_invoke_name' =>'test_template',
			'subject' => '欢迎来到新的世界',
			'resp_email_id' => 'true'
		);

	$data = http_build_query($param);
	$options = array(
		'http' => array(
			'method' => 'POST',
			'header' => 'Content-Type:application/x-www-form-urlencoded',
			'content' => $data
			)
		);
	$context = stream_context_create($optionns);
	$result = file_get_contents($url,FILE_TEXT,$context);
	return $result;
}

echo send_mail();

header("Content-type:text/html;charset=utf-8");
$apikey = '';
$mobile = '18748342258';
$text = '';
$ch = curl_init();

curl_setopt($ch,CURLOPT_HTTPHEADER,array('Accept:text/plain;charset=utf-8','Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

$json_data = get_user($ch,$apikey);
$array = json_decode($json_data,true);
echo '<pre>';
print_r($array);
$data = array('text' => $text, 'apikey' => $apikey, 'mobile' => $mobile);
$json_data = send($ch,$data);
$array = json_decode($json_data,true);
echo '<pre>';
print_r($array);

function get_user($ch,$apikey){
	curl_setopt($ch,CURLOPT_URL,'https://sms.yunpian.com/v1/user/get.json');
	curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array('apikey' => $apikey)));
	return curl_exec($ch);
}

function send($ch,$data){
	curl_setopt($ch,CURLOPT_URL,'https://sms.yunpian.com/v1/sms/send.json');
	crul_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));
	return curl-exec($ch);
}
